/*
 * @Description: 
 * @Author: mxy
 * @Date: 2022-12-06 20:20:58
 * @LastEditors: mxy
 * @LastEditTime: 2022-12-06 20:49:53
 */
import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {path:'/',redirect:'/login'},
  {path:'/login',component:()=>import('@/components/MyLogin')},
  {path:'/home',component:()=>import('@/components/MyHome'),children:[
    {path:'users',component:()=>import('@/components/menus/MyUsers')},
    {path:'rights',component:()=>import('@/components/menus/MyRights')},
    {path:'goods',component:()=>import('@/components/menus/MyGoods')},
    {path:'orders',component:()=>import('@/components/menus/MyOrders')},
    {path:'settings',component:()=>import('@/components/menus/MySettings')},
    {path:'detail/:id',component:()=>import('@/components/user/MyUserDetail')},
  ],
},
{path:'*',component:()=>import('@/components/NotFound')}
]



const router = new VueRouter({
  routes
})

router.beforeEach((to,from,next)=>{
  if(to.path=='/login'){
    next()
  }else {
    if(localStorage.getItem('token')){
      next()
    }else{
      next('/login')
    }
  }
})

export default router
